<?php
class ErrorHandler {
	private static $aErrors = array();
	private static $aFormErrors = array();
	
	public static function addError($sMessage) {
		// For setup purposes
		if ($sMessage == 'SQL error' && DATABASE_OK !== true) {
			return;
		}
		
		// Make sure the error array exists
		if (!is_array(ErrorHandler::$aErrors)) {
			ErrorHandler::$aErrors = array();
		}
		
		// Add the error if it wasn't already added
		if (!in_array($sMessage, ErrorHandler::$aErrors)) {
			array_push(ErrorHandler::$aErrors, $sMessage);
		}
	}
	
	public static function formError($sField, $sMessage) {
		ErrorHandler::$aFormErrors[$sField] = $sMessage;
	}

	public static function hasFormErrors() {
		return (count(ErrorHandler::$aFormErrors) > 0);
	}

	public static function showFormErrors() {
		$sErrors = array();
		$arrArgs = func_get_args();
		foreach ($arrArgs as $sArg) {
			if (array_key_exists($sArg, ErrorHandler::$aFormErrors)) {
				array_push($sErrors, ErrorHandler::$aFormErrors[$sArg]);
			}
		}

		if (count($sErrors) > 0) {
			require('include/classes/error/ui/error.show.ui.php');
		}
	}
	
	public static function getErrors() {
		return ErrorHandler::$aErrors;
	}
}
?>
